<template>
	<view>

		<!-- 	<view class="box" v-for="item in List">
			
			
			
			
			
			<view class="top" @click="navSysDetail(item.id)">


				<u-badge type="error" v-if="item.isRead==0?true:false" :is-dot="true" :offset="['-20','-20']"></u-badge>

				<view class="title">
					{{item.title}}
				</view>
				<view class="">
					{{item.createTime}}
				</view>
			</view>
			
		</view> -->
		<!-- <view class="content">
			{{item.context}}
			欢迎使用抢拍app,更多简便功能将后续开发,请敬请期待!
		</view> -->
		<view class="widthApp">
			
	
		<u-swipe-action :style="widthApp" :index="index" v-for="(item, index) in List" @click="deleteInfo(item.id)" @open="open" :options="options">

			<view class="box">
				<u-badge type="error" v-if="item.isRead==0?true:false" :is-dot="true" :offset="['0','0']"></u-badge>

				<view class="top" @click="navSysDetail(item.id)">

					<view class="title">
						{{item.title}}
					</view>
					<view class="time">
						{{item.createTime}}
					</view>
				</view>
			</view>
		</u-swipe-action>
	</view>

		<view style="height: 30px;"></view>
	</view>
</template>
<script>
	import {
		getSysMsg,
		sysMsgSetIsRead,
		sysMsgSetdetele
	} from '@/api/new.js';

	export default {
		data() {
			return {
				widthApp: {
					width:'100%'
				},
				options: [{
					text: this.$t('system.title.detele'),
					style: {
						backgroundColor: '#dd524d'
					}
				}],
				List: [],
				from: {
					page: 1,
					limit: 20
				}
			}
		},
		onShow() {
			uni.setNavigationBarTitle({
				title: this.$t("system.title")
			})
			this.getList()
		},
		methods: {
			deleteInfo(id) {
				console.log(id,'kkkkkk');
				
				sysMsgSetdetele(id).then(res=>{
					console.log(res,'删除了');
					if(res.code == 200){
						this.from = {
							page: 1,
							limit: 20
						}
						this.List = []
						this.getList()
					}
				})
				// if (index1 == 1) {
					// this.List.splice(index, 1);
				// 	this.$u.toast(`删除了第${index}个cell`);
				// } else {
				// 	this.List[index].show = false;
				// 	this.$u.toast(`收藏成功`);
				// }
			},
			// 如果打开一个的时候，不需要关闭其他，则无需实现本方法
			open(index) {
				// 先将正在被操作的swipeAction标记为打开状态，否则由于props的特性限制，
				// 原本为'false'，再次设置为'false'会无效
				this.List[index].show = true;
				this.List.map((val, idx) => {
					if (index != idx) this.List[idx].show = false;
				})
			},
			getList() {
				getSysMsg(this.from).then(res => {
					console.log(res,'}}}}}}}');
					if (res.code == 200) {
						this.List = [...this.List, ...res.data.list]
						this.List.forEach(item=>{
							switch(item.type){
								case 1:
								item.title = this.$t('system.info.type-1')
								break;
								case 2:
								item.title = this.$t('system.info.type-2')
								break;
								case 3:
								item.title = this.$t('system.info.type-3')
								break;
								case 4:
								item.title = this.$t('system.info.type-4')
								break;
								case 5:
								item.title = this.$t('system.info.type-5')
								break;
								case 7:
								item.title = this.$t('system.info.type-1')
								break;
								case 8:
								item.title = this.$t('system.info.type-1')
								break;
								case 9:
								item.title = this.$t('system.info.type-9')
								break;
							}
						})
						console.log(res.data, 'res.data');
					}
				})
			},
			navSysDetail(id) {
				console.log(id, 'kkkkkkkkkkkkk');
				this.List = []
				this.from.page = 1
				uni.navigateTo({
					url: `/pages/user/setting/systemDetail?id=${id}`
				})
			}
		},
		onReachBottom() {
			this.from.page++
			this.getList()
			console.log('到底了');
		}
	}
</script>
<style lang="scss">
	.widthApp{
		width: 100%;
	}
	.box {
		padding: 5px 10px;
		margin: 5px 10px;
		background: #fff;
		position: relative;
		border-bottom: 1px solid #eee;
		.top {
			position: relative;
			display: flex;
			justify-content: space-between;
			padding: 5px 0;
			align-items: center;
		
			.title {
				font-size: 12px;
				font-weight: bold;
				width: 60%;
			}
			.time{
				flex: 1;
				font-size: 12px;
				display: flex;
				justify-content: flex-end;
			}
		}

		.content {
			padding: 15px 0;
		}
	}
</style>